package com.adou.second.day8;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

/**
 * 递归遍历路径
 * 
 * @author admin
 *
 */
public class FileDemo {

	public static void main(String[] args) {
		List<File> fileList = new ArrayList();
		// 给定路径创建file
		File file = new File("myFile");
		
		
		fileList = getFilePath(file, fileList);
		
		for (int i = 0; i < fileList.size(); i++) {
			System.out.println(fileList.get(i));
		}
		
		
	}
	
	/**
	 * 获取所有文夹中文件
	 * @param file
	 * @return
	 */
	public static List<File> getFilePath(File file, List<File> fileList){
		File[] files = file.listFiles();
		for (int i = 0; i < files.length; i++) {
			if(files[i].isFile()) {
				fileList.add(files[i]);
			} else {
				getFilePath(files[i], fileList);
			}
		}
		
		
		
		return fileList;
	}
	
	

}
